package org.example.utils.market.Commodity;

import org.example.dao.dao.market.CCommodityDao;
import org.example.skytool.redis.RedisUtils;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

import java.util.List;

import static org.example.skytool.redis.RedisConstants.*;

/**
 * @author xluo
 * @date 2023/11/9 7:59
 */
@Component
public class RedisCommodityService {

    @Resource
    private RedisUtils redisUtils;

    @Resource
    private CCommodityDao cCommodityDao;

    public String getCommodityVersionKey() {
        String key = MARKET_MOUDLE + MARKET_COMMODITY_CONTROLLER + MARKET_COMMODITY_VERSION_KIND;
        return key;
    }

    public String getCommodityIdsKey(String version) {
        String key = MARKET_MOUDLE + MARKET_COMMODITY_CONTROLLER + MARKET_COMMODITY_TOTAL_KIND + version;
        return key;
    }

    public String getCommodityContentKey(Long storeId) {
        String key = MARKET_MOUDLE + MARKET_COMMODITY_CONTROLLER + MARKET_COMMODITY_CACHE_KIND + storeId;
        return key;
    }

    public String getCommodityContentLock(Long storeId) {
        String key = MARKET_MOUDLE + MARKET_COMMODITY_CONTROLLER + MARKET_COMMODITY_CACHE_KIND + storeId + "lock";
        return key;
    }

    public void setCommodityIds(List<String> list, String version) {
        redisUtils.listRightAddAll(getCommodityIdsKey(version), list.toArray(new String[0]));
    }

    public void delCommodityIds(String version) {
        redisUtils.del(getCommodityIdsKey(version));
    }

}
